<template>
  <div class="ma-content-block">
    <sa-table ref="crudRef" :options="options" :columns="columns" :searchForm="searchForm">
      <!-- 搜索区 tableSearch -->
      <template #tableSearch>
        <a-col :span="8">
          <a-form-item label="所属活动" field="activity_id">
            <a-select v-model="searchForm.activity_id" :options="postData" placeholder="请选择所属活动" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="会员姓名" field="member_name">
            <a-input v-model="searchForm.member_name" placeholder="请输入会员姓名" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="性别" field="sex">
            <sa-select v-model="searchForm.sex" dict="sex" placeholder="请选择性别" allow-clear />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="手机号码" field="phone_number">
            <a-input v-model="searchForm.phone_number" placeholder="请输入手机号码" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="公司名称" field="company_name">
            <a-input v-model="searchForm.company_name" placeholder="请输入公司名称" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="公司职务" field="company_position">
            <a-input v-model="searchForm.company_position" placeholder="请输入公司职务" />
          </a-form-item>
        </a-col>
        <a-col :span="8">
          <a-form-item label="报名时间" field="signup_time">
            <a-input v-model="searchForm.signup_time" placeholder="请输入报名时间" />
          </a-form-item>
        </a-col>
      </template>

      <!-- Table 自定义渲染 -->
    </sa-table>

    <!-- 编辑表单 -->
    <edit-form ref="editRef" @success="refresh" />
  </div>
</template>

<script setup>
import { onMounted, ref, reactive } from 'vue'
import { Message } from '@arco-design/web-vue'
import EditForm from './edit.vue'
import api from '../api/signup'
import commonApi from '@/api/common'
// 引用定义
const crudRef = ref()
const editRef = ref()
const postData = ref([])

// 搜索表单
const searchForm = ref({
  activity_id: '',
  member_name: '',
  sex: '',
  phone_number: '',
  company_name: '',
  company_position: '',
  signup_time: '',
})


// SaTable 基础配置
const options = reactive({
  api: api.getPageList,
  pk: 'signup_id',
  recycleApi: api.getRecyclePageList,
  rowSelection: { showCheckedAll: true },
  add: {
    show: false,
    auth: ['/signup/signup/save'],
    func: async () => {
      editRef.value?.open()
    },
  },
  edit: {
    show: false,
    auth: ['/signup/signup/update'],
    func: async (record) => {
      editRef.value?.open('edit')
      editRef.value?.setFormData(record)
    },
  },
  delete: {
    show: true,
    auth: ['/signup/signup/destroy'],
    func: async (params) => {
      const resp = await api.delete(params)
      if (resp.code === 200) {
        Message.success(`删除成功！`)
        crudRef.value?.refresh()
      }
    },
    realAuth: ['/signup/signup/realDestroy'],
    realFunc: async (params) => {
      const resp = await api.realDestroy(params)
      if (resp.code === 200) {
        Message.success(`销毁成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  recovery: {
    show: true,
    auth: ['/signup/signup/recovery'],
    func: async (params) => {
      const resp = await api.recovery(params)
      if (resp.code === 200) {
        Message.success(`恢复成功！`)
        crudRef.value?.refresh()
      }
    },
  },
  export: { show: true, url: '/signup/signup/export', auth: ['/signup/signup/export'] },
})

// SaTable 列配置
const columns = reactive([
  { title:'所属活动',dataIndex:'activity_id_text',width:180},
  { title: '会员姓名', dataIndex: 'member_name', width: 180 },
  { title: '性别', dataIndex: 'sex', dict: 'sex', width: 120 },
  { title: '手机号码', dataIndex: 'phone_number', width: 180 },
  { title: '公司名称', dataIndex: 'company_name', width: 180 },
  { title: '公司职务', dataIndex: 'company_position', width: 180 },
  { title: '报名时间', dataIndex: 'signup_time', width: 180 },
])

// 页面数据初始化
const initPage = async () => {
	const postResp = await commonApi.commonGet('/activity/activity/getActivityClass')
	
	postData.value = postResp.data
}

// SaTable 数据请求
const refresh = async () => {
  crudRef.value?.refresh()
}

// 页面加载完成执行
onMounted(async () => {
  initPage()
  refresh()
})
</script>
